import { BIGINT_PG, VARCHAR255_PG, VARCHAR50_PG } from "~/db.pg";

import { ENUM_APP, ENUM_APP_PORT_REST, ENUM_APP_PORT_TCP } from "@/droplet-bus/core.define";
import { GatewayPart } from "@/droplet-bus/core.define";
import { Sortable } from "~/search.match";

export const RiverStockGateway: GatewayPart = {
  app: ENUM_APP.RIVER_STOCK,
  port_tcp: ENUM_APP_PORT_TCP.RIVER_STOCK,
  port_rest: ENUM_APP_PORT_REST.RIVER_STOCK,
};

export type NotchSortable = { notchType: ENUM_TON_NOTCH; notchKey: "count" | "ton"; sorter: Sortable };
export type NotchQuery = { notchType: ENUM_TON_NOTCH; notchKey: "count" | "ton" };
export type NotchQueryCache = { stats: (NotchQuery & { timeUpdated: number; total: number })[] };

/** 库存类型 */
export enum ENUM_TON_NOTCH {
  NONE = -1,

  /** 场地剩余 */
  IN_OUT = 1000,

  /** 待入库 */
  NOT_IN = 2000,

  /** 待加工 */
  NOT_PROCESS = 2001,

  /** 未发货 */
  NOT_OUT = 3000,
}

/** 库存分类及其统计结果 */
export type NotchAble = {
  key: "count" | "ton";
  type: ENUM_TON_NOTCH;
  total: BIGINT_PG;
};

/** 唯一标记某个信息的库存信息
 * @ivid 库存识别号
 */
export type Stockable = {
  name: VARCHAR255_PG;
  norm: VARCHAR255_PG;
  unit: VARCHAR50_PG;

  /** 根据 name|norm|unit|labelStr 产生的 md5 */
  ivid: VARCHAR255_PG;

  /** 标签字符串 */
  labelStr: VARCHAR255_PG;
};
